package com.yrline.pay.services;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import com.yrline.pay.proxy.request.RechargeRequest;
import com.yrline.pay.proxy.response.RechargeResponse;

@Service
public class RechargeServices {
	@Autowired
    public  RedisTemplate<String, Object> redistTemplate;
	@Autowired
	UserServices userServices;
	private static String RECH_key = "RECH_REC";
	private static String RECH_MERI_key = "RECH_MERI";
	
	
	public void saveRecord(RechargeRequest request){
		redistTemplate.opsForHash().put(RECH_MERI_key, request.getMerBillNo(), request);
	}
	
	public void completeRecored(RechargeResponse response){
		if(response.getTrdStatus()==1){
			RechargeRequest _req=(RechargeRequest)	redistTemplate.opsForHash().get(RECH_MERI_key, response.getMerBillNo());
			_req.setTrdAmt(response.getIpsTrdAmt());
			_req.setIpsFee(response.getIpsFee());
			_req.setIpsBillNo(response.getIpsBillNo());
			_req.setIpsDoTime(response.getIpsDoTime());
			redistTemplate.opsForHash().put(RECH_key, _req.getMerBillNo(), _req);
			userServices.addUserMoney(_req.getIpsAcctNo(), _req.getUserType(), response.getIpsTrdAmt(),_req.getDepositType());
		}
	}
	
	public List<RechargeRequest> selectAll(){
		return (List<RechargeRequest>)(List)this.redistTemplate.opsForHash().values(RECH_key);
	}
}
